package pro.cherish.knowledgedemovalid.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import pro.cherish.knowledgedemovalid.entity.UserEntity;

import javax.validation.Valid;

@Api("测试异常")
@Controller
public class TestExceptionController {
    @ApiOperation(value = "处理异常，在controller方法中",notes = "")
    @GetMapping("testUser08")
    public void testUser08(@Valid UserEntity userEntity){
        int a=1/0;
        System.out.println(a);
        System.out.println(userEntity);
    }

    @ExceptionHandler({RuntimeException.class})
    public ModelAndView runtimeException(RuntimeException e) {
        e.printStackTrace();
        return new ModelAndView("MyError");
    }


}
